class PurchaseRequest{
	public double Amount;
	public int Number;
	public String Purchase;
}
class Approver{
//	指向后继者的空引用
	private Approver successor;
//设置后继者的职责链
	public void setSuccessor(Approver successor) {
		this.successor = successor;
	}
	public void processRequest(PurchaseRequest request){
//        将请求传递给后继者
        if (successor!=null){//后继者是否存在
            successor.processRequest(request);
        }
    }
}
class Director extends Approver{
	public void processRequest(PurchaseRequest request){
		if (request.Amount<50000){
//			可以审批
			System.out.println("主任审批了请求");
		}else {
			super.processRequest(request);
		}
	}
}
class VicePresident extends Approver{
	public void processRequest(PurchaseRequest request){
		if (request.Amount<100000){
//			可以审批
			System.out.println("副董事长审批了请求");
		}else {
            super.processRequest(request);
		}
	}
}
class President extends Approver{
	public void processRequest(PurchaseRequest request){
		if (request.Amount<500000){
//			可以审批
			System.out.println("董事长审批了请求");
		}else {
            super.processRequest(request);
		}
	}
}
class Congress extends Approver{
	public void processRequest(PurchaseRequest request){
		if (request.Amount>=500000){
//			可以审批
			System.out.println("例会审批了请求");
		}else {
            super.processRequest(request);
		}
	}
}
public class RS {
	public static void main(String[] args) {
        Director director = new Director();
        VicePresident vicePresident = new VicePresident();
        President president = new President();
        Congress congress = new Congress();

        director.setSuccessor(vicePresident);
        vicePresident.setSuccessor(president);
        president.setSuccessor(congress);
        congress.setSuccessor(null);

        PurchaseRequest request=new PurchaseRequest();
        request.Amount=600000;
        director.processRequest(request);
    }
}
